package com.ac.input.web.action.input;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.caac.core.web.action.BaseAction;
import com.caac.core.web.form.BaseForm;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright AgileCentury 2004</p>
 * <p>Company: AgileCentury</p>
 * @author <a href="mailto:lianzs@tom.com">Lianzs</a>
 * @version 1.0
 */

public class SuggestAction extends BaseAction {
    protected ActionForward doExecute(ActionMapping mapping, BaseForm form,
                                      HttpServletRequest request,
                                      HttpServletResponse response) throws
            Exception {
        String txtValue = request.getParameter("txtValue");
        //log.info(txtValue);
        String sql = "select DWMC from copdwxx t where dwmc like ? and rownum<11 order by dwmc";
        List dmList = this.getJdbcTemplate().queryForList(sql,new String[]{"%"+txtValue+"%"});
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < dmList.size(); i++) {
            Map map = (Map) dmList.get(i);
            sb.append((String)map.get("DWMC"));
            sb.append("#");
        }        
        response.reset();
        response.setContentType("text/html; charset=GBK"); 
        response.setHeader("Cache-Control", "no-cache"); 
        response.setCharacterEncoding("UTF-8"); 
        //response.getOutputStream().write(sb.toString().getBytes());
        
        response.getWriter().write(sb.toString());
        //log.info(sb);
       return null;
    }
}
